﻿using UnityEngine;
using System.Collections;

public class DownloadPicManager : MonoBehaviour 
{
	public UISprite pic;
	public Material mat;
	public PinchZoom2 zoomer;
	public TweenAlpha tweenAlpha;
	void Start()
	{
		OnBtnDownClick();
	}
	int countClick = -1;
	void OnBtnDownClick()
	{
		Debug.Log("OnBtnDownClick");
		DowloadPic dowloadPic = gameObject.AddComponent<DowloadPic>();
		dowloadPic.DownloadCallback += DownloadCallback;
		countClick++;
		dowloadPic.StartGetPicture(countClick);
	}

	void DownloadCallback(WWW www)
	{
		Debug.Log("DownloadCallback");
		pic.atlas.spriteMaterial.mainTexture = www.texture;
		pic.atlas.spriteList[0].height = www.texture.height;
		pic.atlas.spriteList[0].width = www.texture.width;
		pic.SetDimensions(www.texture.width, www.texture.height);
		zoomer.DownloadPicDone();
		tweenAlpha.ResetToBeginning();
		tweenAlpha.Play();
	}
}
